home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / foundation / NSRange.h < prev    next >
Text File  |  1994-05-13  |  962b  |  34 lines

  1. /*    NSRange.h
  2.     Definitions relative to ranges
  3.       Copyright 1993, 1994, NeXT, Inc.
  4.     NeXT, Nov 1993
  5. */
  6.  
  7. #import <foundation/NSObject.h>
  8.  
  9. @class NSString;
  10.  
  11. /* An open struct for specifying a range of items in arrays, strings, etc. */
  12. typedef struct _NSRange {
  13.     unsigned int location;
  14.     unsigned int length;
  15. } NSRange;
  16.  
  17.  
  18. static inline unsigned NSMaxRange(NSRange range) {
  19.     /* Note that this can easily overflow if range.length big */
  20.     return range.location + range.length;
  21. }
  22.  
  23. static inline BOOL NSLocationInRange(unsigned location, NSRange range) {
  24.     return (location >= range.location) && (location < NSMaxRange(range));
  25. }
  26.  
  27. extern NSRange NSUnionRange(NSRange range1, NSRange range2);
  28.  
  29. extern NSRange NSIntersectionRange(NSRange range1, NSRange range2);
  30.     /* !length => ranges don't intersect, and then location is meaningless */
  31.  
  32. extern NSString *NSStringFromRange(NSRange range);
  33.     /* Returns a string of the form: {location = 34; length = 12} */
  34.